package com.snail.controller;

import com.snail.pojo.ChatMessage;
import com.snail.service.BizAiService;
import com.snail.tools.ESsearchTool;
import com.snail.utils.SecurityUtils;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @author cici
 * @description ai的接口
 * @date 2025/8/16 16:34
 */

@RestController
@RequestMapping()
public class AiController {

//    private final ChatClient chatClient;
//
//    @Autowired
//    public AiController(ChatClient.Builder chatClient, ESsearchTool essearchTool) {
//        this.chatClient = chatClient.build().prompt().toolCallbacks(essearchTool).mutate().build();
//    }
    @Autowired
    BizAiService bizAiService;

    @GetMapping(value = "/search",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ServerSentEvent<String>> searchWithAi(@RequestParam String query) {
        return bizAiService.chat(query)
                .map(data -> ServerSentEvent.builder(data).build());
    }
    @GetMapping("/delChat")
    public ResponseEntity<String> deleteChat() {
        return ResponseEntity.ok(bizAiService.del());
    }
    @GetMapping("/getChat")
    public ResponseEntity<List<ChatMessage>> getChat() {
        return ResponseEntity.ok(bizAiService.getChat());
    }




}
